package com.mz.ozy.mvp.presenter;


import android.app.Activity;
import android.content.Context;

import com.mz.ozy.base.BasePresenterImpl;
import com.mz.ozy.bean.BalanceDetailBean;
import com.mz.ozy.bean.BankListFBean;
import com.mz.ozy.bean.ReceiveAccountBean;
import com.mz.ozy.mvp.model.ReceiveAccountModel;
import com.mz.ozy.mvp.view.ReceiveAccountContract;
import com.mz.ozy.net.MyObserver;
import com.mz.ozy.utils.RxUtil;

import okhttp3.ResponseBody;

/**
 * Created by administrator on 2018/12/3.
 */
public class ReceiveAccountPresenter extends BasePresenterImpl<ReceiveAccountContract.View> implements ReceiveAccountContract.Presenter {

    private ReceiveAccountModel mModel;

    public ReceiveAccountPresenter() {
        mModel = new ReceiveAccountModel();
    }


    @Override
    public void saveAccount(Activity activity, String name, String ali, String wechat, String bank_id, String bank_name, String bank_account, String et_code) {
        mModel.saveAccount(activity, name, ali, wechat, bank_id, bank_name, bank_account, et_code)
                .compose(RxUtil.rxSchedulerHelper(mView.<ResponseBody>bindToLifecycle()))
                .subscribe(new MyObserver<BalanceDetailBean>(mView) {
                    @Override
                    public void onSuccesss(BalanceDetailBean bean) {
                        mView.saveAccountSuccess(bean);
                    }
                });
    }

    @Override
    public void queryAccount(Context context) {
        mModel.queryAccount(context)
                .compose(RxUtil.rxSchedulerHelper(mView.<ResponseBody>bindToLifecycle()))
                .subscribe(new MyObserver<ReceiveAccountBean>(mView) {
                    @Override
                    public void onSuccesss(ReceiveAccountBean bean) {
                        mView.queryAccountSuccess(bean);
                    }
                });
    }

    @Override
    public void getBank(Context context) {
        mModel.getBank(context)
                .compose(RxUtil.rxSchedulerHelper(mView.<ResponseBody>bindToLifecycle()))
                .subscribe(new MyObserver<BankListFBean>(mView) {
                    @Override
                    public void onSuccesss(BankListFBean bean) {
                        mView.onGetBankSuccess(bean);
                    }
                });
    }

    @Override
    public void getBIndInfo(Context context, String type,String id) {
        mModel.getBindInfo(context,type,id)
                .compose(RxUtil.rxSchedulerHelper(mView.<ResponseBody>bindToLifecycle()))
                .subscribe(new MyObserver<BankListFBean>(mView) {
                    @Override
                    public void onSuccesss(BankListFBean bean) {
                        mView.onGetBankSuccess(bean);
                    }
                });
    }
}
